--
-- Author: ping.wang
-- Date: 2019-02-26 14:39:11
--
-- RewardMonitorView
--
local ListMenu = require("app.widget.ListMenu")
local RewardMonitorGivePanel = import(".RewardMonitorGivePanel")
local RewardFirstTargetRender = import(".renders.RewardFirstTargetRender")
local fileName = string.getModeName(...)
local ClassRef = class(fileName, app.mvc.ViewBase)

ClassRef.VIEW_ROOT_RES = Res.RewardMonitorScene

function ClassRef:init()

    self._givePanel = RewardMonitorGivePanel.create(self._ui["Panel/give"]) --普通
    self._givePanel:setVisible(false)

    self._ui["Panel/Button_close"]:addClickEventListener(function()
        executeFunc(self._onCloseView)
    end)
    local function operate(op, data)
        --if data.id ~= self._selectedIdx then
            self._selectedIdx = data.id
            if op == "btnClick" then
                --直接刷新give
                self._givePanel:setData(data)
            elseif op == "subBtnClick" then
            end
        --end
    end

    local params = {
        list = self._ui["Panel/ListView"],
        btnClass = RewardFirstTargetRender,
        subBtnClass = RewardFirstTargetRender,
        operate = operate,
        mustHaveTarget = true,
        onlyOpen = true,
        autoHideSecond = true,
    }
    self._activityList = ListMenu.new(params)
end

function ClassRef:initLeftList(listData,curActivityId)
    if self._activityList then
        self._activityList:removeAllMenus()
        local testData = clone(listData)
        local curSelectedId = 1
        for i = 1, #listData do
            testData[i].idx = i
            testData[i].subDatas = {}
            if testData[i].id == curActivityId then
                curSelectedId = i
            end
        end

        self._listData = testData
        self._activityList:refreshList(testData)
        self._activityList:selectBtn(curSelectedId,nil,false)

        self._givePanel:onOperate(self._onOperate)
        self:refreshLeftListRedPoint()
    end
end

--通知去刷新左侧红点
function ClassRef:refreshLeftListRedPoint()
    for k,v in ipairs(self._listData) do
        self._activityList:setBtnRedPoint(k,nil,v.redPoint > 0)
    end
end

function ClassRef:refreshDataAfterGetTaskAward(data)
    self:initLeftList(data,self._selectedIdx)
end

return ClassRef
